Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port TypeDescriptor benchmarks #83

Merged
merged 9 commits into from
Jul 11, 2018
Merged

Conversation

adamsitnik
Copy link
Member

Fixes #48

This an excellent example why benchmarks MUST NOT contain any Asserts. I have ported the benchmarks and removed the asserts and BDN reported 1/7 of the time reported by xunit-performance.

I was shocked!

And then I used ILSpy to see what Assert was being used in the benchmark. The one from full xunit framework ;)

using (iteration.StartMeasurement())
    for (int i = 0; i < innerIterations; i++)
    {
        TypeConverter converter = TypeDescriptor.GetConverter(typeToConvert);
        Assert.NotNull(converter);
        Assert.Equal(expectedConverter, converter.GetType());
        Assert.True(converter.CanConvertTo(typeof(string)));
    }

So Asserts were 6/7 of the benchmarked time ;)

I did not have to port the Asserts to CoreFX because they are already there (each case has it's own test class)

Method typeToConvert expectedConverter Mean Error StdDev Median Min Max Gen 0 Allocated
GetConverter ClassIDerived IBaseConverter 19.54 us 1.2412 us 1.4294 us 18.99 us 18.21 us 22.86 us 0.5833 3.91 KB
GetConverter ClassWithNoConverter TypeConverter 17.92 us 0.3542 us 0.3637 us 17.70 us 17.56 us 18.46 us 0.5910 3.91 KB
GetConverter DerivedClass DerivedClassConverter 26.54 us 1.6099 us 1.7894 us 25.61 us 24.33 us 30.00 us 0.5692 3.91 KB
GetConverter IDerived IBaseConverter 15.97 us 0.3967 us 0.4409 us 15.74 us 15.61 us 16.84 us 0.5934 3.91 KB
GetConverter SomeEnum EnumConverter 34.05 us 0.7000 us 0.7188 us 33.55 us 33.37 us 35.04 us 0.5896 3.91 KB
GetConverter Enum EnumConverter 27.20 us 0.6635 us 0.6813 us 26.97 us 26.82 us 29.44 us 0.5744 3.91 KB
GetConverter Guid GuidConverter 27.25 us 0.5298 us 0.5203 us 26.94 us 26.82 us 28.03 us 0.5000 3.91 KB
GetConverter Int32 Int32Converter 27.22 us 0.5965 us 0.6383 us 26.90 us 26.72 us 28.86 us 0.6033 3.91 KB
GetConverter SomeValueType? NullableConverter 25.83 us 1.4700 us 1.6929 us 25.29 us 24.38 us 29.72 us 0.5379 3.91 KB
GetConverter Int32? NullableConverter 25.03 us 1.1559 us 1.2368 us 24.47 us 24.28 us 28.14 us 0.5521 3.91 KB
GetConverter String StringConverter 18.87 us 0.5419 us 0.5799 us 18.83 us 18.31 us 20.12 us 0.5704 3.91 KB

I also removed duplicated test cases, which were benchmarking same execiton path.

/cc @jorive

[Arguments(typeof(ClassIBase), typeof(IBaseConverter))]
[Arguments(typeof(ClassIDerived), typeof(IBaseConverter))]
[Arguments(typeof(Uri), typeof(UriTypeConverter))]
public TypeConverter GetConverter(Type typeToConvert, Type expectedConverter) // the expectedConverter argument is not used anymore, but kept to remain BenchView ID, do NOT remove
Copy link
Member

@jorive jorive Jul 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// [](start = 86, length = 2)

Should we remove this and start a fresh/clean benchmark? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the expectedConverter argument?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or in general?

Copy link
Member

@jorive jorive Jul 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the expectedConverter unused variable. #Closed

Copy link
Member

@jorive jorive Jul 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, this would be a good opportunity to start a cleaner/newer benchmark too. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, this would be a good opportunity to start a cleaner/newer benchmark too.

hmm, since after removing the Asserts from the benchmark the time is 1/7 of what it was before, I can remove this argument and rename the benchmark

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorive I have removed the unused argument and removed the inner iteration count to let BDN do the job (it's a new benchmark after rename so I could do that)

Copy link
Member

@jorive jorive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@adamsitnik adamsitnik merged commit 4196ee7 into dotnet:master Jul 11, 2018
@adamsitnik adamsitnik deleted the typeDescriptor branch October 17, 2018 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants